<template>
  <div>
    <!-- 这是个人中心 -->
    <!-- 个人中心的蓝色背景 -->
    <div class="bgblue">
      <img src="" alt="" />
      没有图片背景来凑
    </div>
    <!-- 下面主体定位的大盒子 -->
    <div class="dingwei">
      <!-- 用户信息部分 -->
      <div class="xinxi">
        <div class="shang">
          <div class="touxiang">
            <img :src="srcImgOne" alt="" />
          </div>
          <span>{{ userInfo.remark }}</span>
        </div>
        <div class="xia">
          <div class="name">
            <span>姓名</span>
            <span>{{ userInfo.nickName }}</span>
          </div>
          <div class="telep">
            <span>联系方式</span>
            <span>{{ userInfo.phone }}</span>
          </div>
        </div>
      </div>
      <!-- 下方各个功能部分 -->
      <div class="gongneng">
        <ul>
          <li @click="userInfoGo">
            <img :src="srcImgTwo" alt="" />
            <span>个人信息</span>
            <span>&gt;</span>
          </li>
          <li>
            <img :src="srcImgThree" alt="" />
            <span>支付中心</span>
            <span>&gt;</span>
          </li>
          <li>
            <img :src="srcImgFour" alt="" />
            <span>修改密码</span>
            <span>&gt;</span>
          </li>
          <li @click="banben">
            <img :src="srcImgTwo" alt="" />
            <span>版本信息</span>
            <span>&gt;</span>
            <span>版本{{ banbenVal }}&nbsp;</span>
          </li>
          <li>
            <img :src="srcImgFive" alt="" />
            <span>清除缓存</span>
            <span>&gt;</span>
          </li>
        </ul>
      </div>
      <!-- 退出登录的按钮 -->
      <van-button color="#bbb" size="large" @click="tuichu"
        >退出登录</van-button
      >
    </div>
    <!-- 这是tab模块 -->
    <tab-bar />
    <router-view></router-view>
  </div>
</template>

<script>
import TabBar from "@/components/TabBar.vue";
import { GetUserLists, GetUserBanbenLists } from "@/request/api";
export default {
  components: { TabBar },
  data() {
    return {
      srcImgOne: require("@/assets/touxiang.png"),
      srcImgTwo: require("@/assets/usrinfo.png"),
      srcImgThree: require("@/assets/qianbao.png"),
      srcImgFour: require("@/assets/mima.png"),
      srcImgFive: require("@/assets/qingchu.png"),
      userInfo: "",
      banbenVal: "",
    };
  },
  // 发送请求，渲染当前页面
  created() {
    GetUserLists().then((res) => {
      // console.log(res);
      this.userInfo = res.data;
    });
    // 版本信息的请求
    GetUserBanbenLists().then((res) => {
      this.banbenVal = res.data.versions;
    });
  },
  methods: {
    // 退出登录事件
    tuichu() {
      this.$dialog
        .confirm({
          message: "是否退出登录",
        })
        .then(() => {
          localStorage.removeItem("token");
          let token = localStorage.getItem("token");
          if (!token) {
            this.$router.push("/login");
          }
        })
        .catch(() => {
          console.log("退出失败");
        });
    },
    // 跳转到个人的详细信息页面
    userInfoGo() {
      this.$router.push("/user/userxinxi");
    },
    // 跳转到版本信息页面
    banben() {
      this.$router.push("/user/userbanben");
    },
  },
};
</script>
 
<style lang = "less" scoped>
/* 头部背景图片 */
.bgblue {
  height: 1.5rem;
  width: 100%;
  background-color: #0a368c;
  color: antiquewhite;
}
/* 用于定位的大盒子 */
.dingwei {
  width: 90%;
  position: fixed;
  top: 0.9rem;
  left: 5%;
  /* 上面用户信息的部分 */
  .xinxi {
    height: 1.5rem;
    width: 100%;
    background-color: white;
    padding: 0 0.1rem;
    box-sizing: border-box;
    .shang {
      height: 1rem;
      width: 100%;
      border-bottom: 1px solid #efefef;
      text-align: center;
      span {
        line-height: 1.5rem;
      }
      /* 头像样式 */
      .touxiang {
        height: 1rem;
        width: 1rem;
        border-radius: 50%;
        position: absolute;
        top: -0.5rem;
        left: 50%;
        margin-left: -0.5rem;
        img {
          width: 100%;
        }
      }
    }
    .xia {
      width: 100%;
      display: flex;
      justify-content: space-between;
      span {
        line-height: 0.5rem;
        &:nth-child(1) {
          color: #aaa;
          margin-right: 0.05rem;
        }
      }
    }
  }
  /* 功能列表样式 */
  .gongneng {
    width: 100%;
    background: white;
    margin-top: 0.1rem;
    ul {
      li {
        width: 100%;
        padding: 0.1rem 0.2rem;
        box-sizing: border-box;
        border-bottom: 1px solid #ccc;
        font-size: 16px;
        /* line-height: 20px; */
        img {
          height: 20px;
          vertical-align: -4px;
          margin-right: 0.05rem;
        }
        span {
          &:nth-child(3) {
            float: right;
          }
          &:nth-child(4) {
            float: right;
            color: #aaa;
          }
        }
      }
    }
  }
}
.van-button {
  position: fixed;
  bottom: 90px;
  width: 90%;
}
</style>